using DemoWebapi01.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace DemoWebapi01.EntityTypeConfiguration
{
    public class QuestionETConfig : BaseEntityETConfig<Question>
    {
        protected override void ConfigureOtherProperties(EntityTypeBuilder<Question> builder)
        {
            // 配置基本属性
            builder.Property(e => e.Content)
                .IsRequired()
                .HasComment("问题内容");

            builder.Property(e => e.ContentCN)
                .HasComment("问题内容(中文)");

            builder.Property(e => e.QuestionType)
                .IsRequired()
                .HasMaxLength(20)
                .HasDefaultValue("single_choice")
                .HasComment("问题类型：单选、多选、判断、填空、简答");

            builder.Property(e => e.Difficulty)
                .IsRequired()
                .HasMaxLength(10)
                .HasDefaultValue("medium")
                .HasComment("难度：简单、中等、困难");

            builder.Property(e => e.Explanation)
                .HasComment("解析");

            builder.Property(e => e.ExplanationCN)
                .HasComment("解析(中文)");

            builder.Property(e => e.Status)
                .HasMaxLength(20)
                .HasDefaultValue("active")
                .HasComment("状态：活跃、非活跃、待审核");

            builder.Property(e => e.CategoryId)
                .IsRequired()
                .HasComment("分类ID");

            // 配置与Category的关系
            builder.HasOne(x => x.Category)
                .WithMany(c => c.Questions)
                .HasForeignKey(q => q.CategoryId)
                .OnDelete(DeleteBehavior.Restrict) // 防止误删除引用的分类
                .HasConstraintName("FK_Question_Category");
        }
    }
}